/*
	The MIT License

	Copyright (c) 2010 IFMO/GameDev Studio

	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.
*/

#pragma once

/*-----------------------------------------------------------------------------
	D3D driver :
-----------------------------------------------------------------------------*/

struct  EVidModeDesc_s {
		uint	width;
		uint	height;
		bool	is_supported;
	};

struct  EVidState_s	{
		bool	fullscr;
		int		mode;
		HWND	h_wnd;
	};



class ED3DDriver : public IRSDriver {
	public:
								ED3DDriver		( void );
								~ED3DDriver		( void );
	
		virtual void			ResetState		( void );
	
		virtual bool			CheckFeature	( ERSFeature feature );
		virtual void			GetScreenSize	( uint &w, uint &h );
		virtual void		*	GetWindowHandle	( void );
		
		virtual IPxTXManager	GetTXM			( void ) { return txm; }
		virtual IPxRTManager	GetRTM			( void ) { return rtm; }
		virtual IPxVBManager	GetVBM			( void ) { return vbm; }
		virtual IPxFXManager	GetFXM			( void ) { return fxm; }
		
		virtual bool			BeginFrame		( void );
		virtual void			EndFrame		( void );
		
	public:
		LPDIRECT3DDEVICE9		GetDevice		( void ) { return d3ddev; }
		LPDIRECT3DSURFACE9		ColorSurface	( void ) { return default_color_surf; }
		LPDIRECT3DSURFACE9		DepthSurface	( void ) { return default_depth_surf; }
		
		bool					RestoreDevice	( void );
	
	protected:
		void				InitDisplay			( void );
		void				InitDirect3D		( void );
		void				ShutdownDisplay		( void );
		void				ShutdownDirect3D	( void );
		void				CheckDisplayModes	( void );
		
		IPxTXManager		txm;
		IPxRTManager		rtm;
		IPxVBManager		vbm;
		IPxFXManager		fxm;
		
		LPDIRECT3DSURFACE9		default_color_surf;
		LPDIRECT3DSURFACE9		default_depth_surf;

		LPDIRECT3D9				d3d;
		LPDIRECT3DDEVICE9		d3ddev;
	    D3DPRESENT_PARAMETERS	d3dpp; 

		static LRESULT	WndProc				( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
		EVidState_s		vid_state;		

		IPxVar	d3d_fullscr;
		IPxVar	d3d_mode;
		IPxVar	d3d_xpos;
		IPxVar	d3d_ypos;
		IPxVar	d3d_antialiasing;
	};